﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SGArchiveSystem7x.Models
{
    /// <summary>
    /// 下拉框的数据类
    /// </summary>
    public class CComboboxModel
    {
        /* 下拉框属性
         * 1. ID:  下拉框内容的VALUE
         * 2. Text: 下拉框内容的显示
         */

        #region 下拉框属性
        /// <summary>
        /// 下拉框的值 
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 下拉框显示的内容
        /// </summary>
        public string Text { get; set; }
        #endregion


        #region 具体每个下拉框的建立
        /// <summary>
        /// 初始化下拉框值，并且确定是否要添加一个叫全部的值
        /// </summary>
        /// <param name="bAddAll"></param>
        /// <returns></returns>
        private static List<CComboboxModel> CreateNewModelAndAddAll(bool bAddAll)
        {
            List<CComboboxModel> list = new List<CComboboxModel>();
            if (bAddAll)
            {
                if (Models.Language._nowLanguage == SGArchiveSystem7xDB._VersionLanguage._Chs)
                    list.Add(new CComboboxModel() { ID = -1, Text = "全部" });
                else
                    list.Add(new CComboboxModel() { ID = -1, Text = "ALL" });
            }
            return list;
        }

        #region 建立部门下拉框
        /// <summary>
        /// 建立部门下拉框
        /// </summary>
        /// <param name="bAddAll">是否要增加一个全部的下拉值，如果是全部，那么ID为-1</param>
        /// <param name="bAddHaveChild">如果部门下有子部门的，如果是T，那么既添加主部门又添加子部门，如果是F那么只添加子部门，而不添加主部门</param>
        /// <returns></returns>
        public static List<CComboboxModel> Create_ComboboxDepartment(bool bAddAll, bool bAddHaveChild)
        {
            int count = 0;
            var listDep = SGArchiveSystem7xDB.Linq.T_DeparetmentDal.Get_Department(out count);
            List<CComboboxModel> list = CreateNewModelAndAddAll(bAddAll);
            if (listDep != null)
            {
                foreach (var en in listDep)
                {
                    if (!bAddHaveChild)
                    {
                        if (en.Dep_I01 != 1)
                        {
                            CComboboxModel n = new CComboboxModel() { ID = en.Dep_ID, Text = en.Dep_Name };
                            list.Add(n);
                        }
                    }
                    else
                    {
                        CComboboxModel n = new CComboboxModel() { ID = en.Dep_ID, Text = en.Dep_Name };
                        list.Add(n);
                    }
                }
            }
            return list;
        }
        #endregion

        #region 建立角色下拉框
        /// <summary>
        /// 建立角色下拉框
        /// </summary>
        /// <param name="bAddAll"></param>
        /// <returns></returns>
        public static List<CComboboxModel> Create_ComboboxRole(bool bAddAll)
        {
            int count = 0;
            var listRole = SGArchiveSystem7xDB.Linq.T_RoleDal.Get_Role(out count);
            List<CComboboxModel> list = CreateNewModelAndAddAll(bAddAll);
            if (listRole != null)
            {
                foreach (var en in listRole)
                {
                    CComboboxModel n = new CComboboxModel() { ID = en.ROLE_ID, Text = en.ROLE_NAME };
                    list.Add(n);
                }
            }
            return list;
        }
        #endregion

        #region 建立档案树下拉框
        /// <summary>
        /// 建立角色下拉框
        /// </summary>
        /// <param name="bAddAll"></param>
        /// <returns></returns>
        public static List<CComboboxModel> Create_ComboboxArchiveTree(bool bAddAll)
        {
            int count = 0;
            var listArchiveTree = SGArchiveSystem7xDB.Linq.T_ArchiveTreeDal.Get_ArchiveTree(-1, 1);
            List<CComboboxModel> list = CreateNewModelAndAddAll(bAddAll);
            if (listArchiveTree != null)
            {
                foreach (var en in listArchiveTree)
                {
                    CComboboxModel n = new CComboboxModel() { ID = en.AR_ID, Text = en.AR_NAME };
                    list.Add(n);
                }
            }
            return list;
        }
        #endregion

        #region 建立词典类型下拉框
        /// <summary>
        /// 建立词典类型下拉框
        /// </summary>
        /// <param name="bAddAll"></param>
        /// <returns></returns>
        public static List<CComboboxModel> Create_ComboboxWordTypeTree(bool bAddAll)
        {
            var listWordType = SGArchiveSystem7xDB.Linq.T_ArchiveWordTypeDal.Get_ArchiveWordType(1);
            List<CComboboxModel> list = CreateNewModelAndAddAll(bAddAll);
            if (listWordType != null)
            {
                foreach (var en in listWordType)
                {
                    CComboboxModel n = new CComboboxModel() { ID = en.WT_ID, Text = en.WT_NAME };
                    list.Add(n);
                }
            }
            return list;
        }
        #endregion

        #region 利用目的下拉框
        /// <summary>
        /// 利用目的
        /// </summary>
        /// <param name="bAddAll"></param>
        /// <returns></returns>
        public static List<CComboboxModel> Create_ComboboxLYMD(bool bAddAll)
        {
            int count = 0;
            var listWord = SGArchiveSystem7xDB.Linq.T_ArchiveWordDal.Get_ArchiveWord(out count, 4, -1, -1);
            List<CComboboxModel> list = CreateNewModelAndAddAll(bAddAll);
            if (listWord != null)
            {
                foreach (var en in listWord)
                {
                    CComboboxModel n = new CComboboxModel() { ID = en.WD_ID, Text = en.WD_NAME };
                    list.Add(n);
                }
            }
            return list;
        }
        #endregion
        
        #region 系统主模块的下拉框
        /// <summary>
        /// 获取主模块下拉框
        /// </summary>
        /// <param name="bAddAll"></param>
        /// <returns></returns>
        public static List<CComboboxModel> Create_ComboboxMainModel(bool bAddAll)
        {
            var listType = SGArchiveSystem7xDB.Linq.T_ModelDal.Get_Model(1, 0);
            List<CComboboxModel> list = CreateNewModelAndAddAll(bAddAll);
            if(listType != null)
            {
                foreach(var en in listType)
                {
                    CComboboxModel n = new CComboboxModel() { ID = en.MD_ID, Text = en.MD_NAME };
                    list.Add(n);
                }
            }
            return list;
        }
        #endregion

        #region 档案密级的下拉框
        // <summary>
        /// 获取主模块下拉框
        /// </summary>
        /// <param name="bAddAll"></param>
        /// <returns></returns>
        public static List<CComboboxModel> Create_ComboboxMJ(bool bAddAll)
        {
            int count = 0;
            var listType = SGArchiveSystem7xDB.Linq.T_ArchiveWordDal.Get_ArchiveWord(out count,2, -1, -1);
            
            List<CComboboxModel> list = CreateNewModelAndAddAll(bAddAll);
            if (listType != null)
            {
                foreach (var en in listType)
                {
                    CComboboxModel n = new CComboboxModel() { ID = en.WD_ID, Text = en.WD_NAME };
                    list.Add(n);
                }
            }
            return list;
        }
        #endregion
        #endregion
    }
}